import argparse
from PyQt5 import QtCore, QtWidgets
from QTdesigner.MainWindow import MainWindow
import sys
import cv2 as cv


if __name__ == '__main__':

    parser = argparse.ArgumentParser()
    parser.add_argument('--weights', nargs='+', type=str,
                        default='models\\miner.pt', help='model.pt path(s)')
    parser.add_argument(
        '--source', type=str, default='', help='source')
    parser.add_argument('--img-size', type=int, default=640,
                        help='inference size (pixels)')
    parser.add_argument('--conf-thres', type=float,
                        default=0.25, help='object confidence threshold')
    parser.add_argument('--iou-thres', type=float,
                        default=0.4, help='IOU threshold for NMS')
    parser.add_argument('--device', default='',
                        help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
    parser.add_argument('--show', action='store_true', help='display results')
    parser.add_argument('--classes', nargs='+', type=int,
                        help='filter by class: --class 0, or --class 0 2 3')
    parser.add_argument('--project', default='runs/detect',
                        help='save results to project/name')
    parser.add_argument('--name', default='exp',
                        help='save results to project/name')
    opt = parser.parse_args()

    print(opt)

    if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'):
        QtWidgets.QApplication.setAttribute(
            QtCore.Qt.AA_EnableHighDpiScaling, True)
    if hasattr(QtCore.Qt, 'AA_UseHighDpiPixmaps'):
        QtWidgets.QApplication.setAttribute(
            QtCore.Qt.AA_UseHighDpiPixmaps, True)

    app = QtWidgets.QApplication(sys.argv)
    mainWin = MainWindow(None, opt.source, opt.weights,
                         opt.img_size, opt.conf_thres, opt.iou_thres, opt.device)
    mainWin.show()
    sys.exit(app.exec_())

    # user, pwd, channel = "admin", "Jdk111111", 2
    # ip = "192.168.7.21"
    # # HIKIVISION new version 2017
    # capIP1 = "rtsp://%s:%s@%s//Streaming/Channels/%d" % (
    #         user, pwd, ip, channel)
    # # 暂时用视频模拟相机图像
    # cap1 = cv.VideoCapture(capIP1)

    # while(True):
    #     ret, img = cap1.read()
    #     cv.imshow("frame", img)

    #     if cv.waitKey(30) == 27:
    #         if cv.waitKey(0) ==27:
    #             break
